/*
 *  Copyright 2008-2010 the original author or authors.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.openaecfm.spf.io.measure;

import org.openaecfm.model.measure.DimensionalExponents;
import org.openaecfm.spf.io.AbstractEntityInstanceInputImpl;
import org.openaecfm.spf.io.IAppDataManager;
import org.openaecfm.spf.io.IEntityInstanceOutput;
import org.openaecfm.spf.model.EntityInstance;
import org.openaecfm.spf.model.IntegerParameter;
import org.openaecfm.spf.model.SimpleEntityInstance;

public final class DimensionalExponentsIO extends
		AbstractEntityInstanceInputImpl<DimensionalExponents> implements
		IEntityInstanceOutput<DimensionalExponents> {
	/**
	 * {@inheritDoc}
	 */
	@Override
	public String exportSPF(DimensionalExponents pojo,
			IAppDataManager appDataManager) {
		SimpleEntityInstance ei = new SimpleEntityInstance(
				"IFCDIMENSIONALEXPONENTS", appDataManager.getName(pojo));

		// Set LengthExponent
		IntegerParameter length = new IntegerParameter(pojo.getLengthExponent());
		ei.addParameter(length);

		// Set MassExponent
		IntegerParameter mass = new IntegerParameter(pojo.getMassExponent());
		ei.addParameter(mass);

		// Set TimeExponent
		IntegerParameter time = new IntegerParameter(pojo.getTimeExponent());
		ei.addParameter(time);

		// Set ElectricCurrentExponent
		IntegerParameter electric = new IntegerParameter(
				pojo.getElectricCurrentExponent());
		ei.addParameter(electric);

		// Set ThermodynamicTemperatureExponent
		IntegerParameter thermodynamic = new IntegerParameter(
				pojo.getThermodynamicTemperatureExponent());
		ei.addParameter(thermodynamic);

		// Set AmountOfSubstanceExponent
		IntegerParameter amount = new IntegerParameter(
				pojo.getAmountOfSubstanceExponent());
		ei.addParameter(amount);

		// Set LuminousIntensityExponent
		IntegerParameter luminous = new IntegerParameter(
				pojo.getLuminousIntensityExponent());
		ei.addParameter(luminous);

		return ei.toString();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected DimensionalExponents doCreateObject() {
		return new DimensionalExponents();
	}

	@Override
	public void resolveReferenceParameter(EntityInstance ei,
			DimensionalExponents pojo, IAppDataManager appDataManager) {
		return;
	}

	@Override
	protected void resolveNotReferenceParameter(EntityInstance ei,
			DimensionalExponents pojo) {
		SimpleEntityInstance sei = (SimpleEntityInstance) ei;

		// Set LengthExponent
		IntegerParameter length = (IntegerParameter) sei.getParameter(0);
		pojo.setLengthExponent(length.toInteger());

		// Set MassExponent
		IntegerParameter mass = (IntegerParameter) sei.getParameter(1);
		pojo.setMassExponent(mass.toInteger());

		// Set TimeExponent
		IntegerParameter time = (IntegerParameter) sei.getParameter(2);
		pojo.setTimeExponent(time.toInteger());

		// Set ElectricCurrentExponent
		IntegerParameter electric = (IntegerParameter) sei.getParameter(3);
		pojo.setElectricCurrentExponent(electric.toInteger());

		// Set ThermodynamicTemperatureExponent
		IntegerParameter thermodynamic = (IntegerParameter) sei.getParameter(4);
		pojo.setThermodynamicTemperatureExponent(thermodynamic.toInteger());

		// Set AmountOfSubstanceExponent
		IntegerParameter amount = (IntegerParameter) sei.getParameter(5);
		pojo.setAmountOfSubstanceExponent(amount.toInteger());

		// Set LuminousIntensityExponent
		IntegerParameter luminous = (IntegerParameter) sei.getParameter(6);
		pojo.setLuminousIntensityExponent(luminous.toInteger());
	}
}
